package com.atguigu.commonutils;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author : 李红磊
 * @Date : 2021/06/03/0:04
 * @Description :统一结果返回
 */
@Data
public class CommonResult {

    @ApiModelProperty(value = "是否成功")
    private Boolean success;

    @ApiModelProperty(value = "返回码")
    private Integer code;

    @ApiModelProperty(value = "返回消息")
    private String message;

    @ApiModelProperty(value = "返回数据")
    private Map<String, Object> data = new HashMap<String, Object>();

    private CommonResult(){}

    public static CommonResult ok(){
        CommonResult result = new CommonResult();
        result.setSuccess(true);
        result.setCode(ResultCode.SUCCESS);
        result.setMessage("成功");
        return result;
    }


    public static CommonResult error(){
        CommonResult result = new CommonResult();
        result.setSuccess(false);
        result.setCode(ResultCode.ERROR);
        result.setMessage("失败");
        return result;
    }




    public CommonResult success(Boolean success){
        this.setSuccess(success);
        return this;
    }
    public CommonResult message(String message){
        this.setMessage(message);
        return this;
    }
    public CommonResult code(Integer code){
        this.setCode(code);
        return this;
    }
    public CommonResult data(String key, Object value){
        this.data.put(key, value);
        return this;
    }
    public CommonResult data(Map<String, Object> map) {
        this.setData(map);
        return this;
    }



    
}
